package com.hedl.practice.diyJava.exception;

public class StudyThrowException {
    public static void main(String[] args) throws Exception {

       /* try{
            process1();
        }catch(Exception e){
            e.printStackTrace();
        }*/

        //如果在try或者catch语句块中抛出异常，finally语句是否会执行？
        /*try{
            Integer.parseInt("abc");
        }catch (Exception e){
            System.out.println("catched");
            throw new RuntimeException(e);
        }finally{
            System.out.println("finally");
        }*/

        //异常屏蔽
        /*try{
            Integer.parseInt("abc");
        }catch(Exception e){
            System.out.println("catched");
            throw new RuntimeException(e);
        }finally{
            System.out.println("finally");
            throw new IllegalArgumentException();
        }*/

        //获取所有异常信息
        Exception origin = null;
        try{
            System.out.println(Integer.parseInt("abc"));
        }catch (Exception e){
            origin = e;
            throw e;
        }finally{
            Exception e = new IllegalArgumentException();
            if (origin != null){
                e.addSuppressed(origin);
            }
            throw e;
        }
    }

    /*static void process1(){
        try{
            process2();
        }catch (NullPointerException e){       //空指针异常
            throw new IllegalArgumentException(e);       //非法参数异常
        }
    }

    static void process2(){
        //Integer.parseInt(null);     //NumberFormatException
        throw new NullPointerException();
    }*/
}
